package com.fang.testProvider;

import com.fang.Utils.MyUtils;
import com.fang.bean.UserInfoBean;
import com.fang.dao.UserInfoBeanMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class testDriver {

    @Test
    public void test05(){
        String resource = "mybatis-config.xml";
        try {
            InputStream inputStream = Resources.getResourceAsStream(resource);
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            SqlSession session = sqlSessionFactory.openSession();
            UserInfoBeanMapper userInfoBeanMapper= session.getMapper(UserInfoBeanMapper.class);
            UserInfoBean userInfoBean = new UserInfoBean();
            userInfoBean.setUsername("user");
            userInfoBean.setUseraddress("青");
            List<UserInfoBean> list = userInfoBeanMapper.queryListLike3(userInfoBean,true);
            for (UserInfoBean user:list
            ) {
                System.out.println(user);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void test04(){
        String resource = "mybatis-config.xml";
        try {
            InputStream inputStream = Resources.getResourceAsStream(resource);
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            SqlSession session = sqlSessionFactory.openSession();
            UserInfoBeanMapper userInfoBeanMapper= session.getMapper(UserInfoBeanMapper.class);
            UserInfoBean userInfoBean = new UserInfoBean();
            userInfoBean.setUsername("user");
            userInfoBean.setUseraddress("青");
            List<UserInfoBean> list = userInfoBeanMapper.queryListLike2(userInfoBean);
            for (UserInfoBean user:list
                 ) {
                System.out.println(user);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }



    @Test
    public void test03(){
        String resource = "mybatis-config.xml";
        try {
            InputStream inputStream = Resources.getResourceAsStream(resource);
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            SqlSession session = sqlSessionFactory.openSession();
            UserInfoBeanMapper userInfoBeanMapper= session.getMapper(UserInfoBeanMapper.class);

            UserInfoBean user = userInfoBeanMapper.selectByPrimaryKey2("user103","山东淄博");
            System.out.println(user);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }




    @Test
    public void test02(){
        String resource = "mybatis-config.xml";
        try {
            InputStream inputStream = Resources.getResourceAsStream(resource);
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            SqlSession session = sqlSessionFactory.openSession();
            UserInfoBeanMapper userInfoBeanMapper= session.getMapper(UserInfoBeanMapper.class);
           UserInfoBean userInfoB = new UserInfoBean();
           userInfoB.setUsername("user");
           userInfoB.setUseraddress("淄");
           userInfoB.setUsertel("1");
            userInfoB.setRegdate(MyUtils.String2Date("2020-04-16","yyyy-MM-dd"));
            userInfoB.setRegdate2(MyUtils.String2Date("2020-04-19","yyyy-MM-dd"));
            List<UserInfoBean> list = userInfoBeanMapper.queryListLike(userInfoB);
            for (UserInfoBean user:list
            ) {
                System.out.println(user);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    @Test
    public void test01(){
        String resource = "mybatis-config.xml";
        try {
            InputStream inputStream = Resources.getResourceAsStream(resource);
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            SqlSession session = sqlSessionFactory.openSession();
            UserInfoBeanMapper userInfoBeanMapper= session.getMapper(UserInfoBeanMapper.class);
           /* UserInfoBean userInfoB = new UserInfoBean();
            userInfoB.setUserid(2);
            userInfoB.setUserid(6);
            userInfoB.setUserid(10);*/
            List<Integer> lst = new ArrayList<>();
            lst.add(2);
            lst.add(6);
            lst.add(10);
            List<UserInfoBean> list = userInfoBeanMapper.listUserInfoBean(lst);
            for (UserInfoBean user:list
                 ) {
                System.out.println(user);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
